home *** CD-ROM | disk | FTP | other *** search
/ DarkBASIC - The Ultimate 3D Game Creator / PCactive 8 CD1 - DarkBasic.iso / SOFTWARE / DEMOS / DarkForge2000 / darkfractals / darkfractals.dba next >
Encoding:
Text File  |  2000-03-23  |  1.6 KB  |  80 lines

  1. ` -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  2. `             Dark Fractals
  3. ` -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  4. ` By Rich Davey (rich@fatal-design.com)
  5. ` -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  6. ` My thanks to BjornLynne for providing
  7. ` the music during the coding of this !
  8. ` -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  9.  
  10. sync rate 0
  11. sync on
  12. hide mouse
  13.  
  14. cls rgb(255,255,255)
  15.  
  16. start_time=timer()
  17.  
  18. MinX#=-1.75; MaxX#=1.75; MinY#=-1.75; MaxY#=1.75
  19.  
  20. ` Uncomment the following (and comment the line above)
  21. ` for a more zoomed-in fractal. Play with the values for different patterns
  22. ` MaxX and MaxY = zoom, MinX and MinY = alignment
  23. `
  24. ` MinX#=-2.75; MaxX#=2.75; MinY#=-2.75; MaxY#=2.75
  25.  
  26. `    Start drawing
  27.  
  28.     dx#=(MaxX#-MinX#)/640
  29.     dy#=(Maxy#-MinY#)/480
  30.  
  31.     for y=0 to 480-1
  32.         for x=0 to 640-1
  33.             pixel_color#=calc_pixel(MinX#+x*dx#,MinY#+y*dy#)*20
  34.             ink rgb(pixel_color#,0,pixel_color#),rgb(0,0,0)
  35.            dot x,y
  36.         next x
  37.         sync
  38.     next y
  39.  
  40.     end_timer=timer()
  41.  
  42. `    Show time to render
  43.  
  44.     set cursor 0,0
  45.     ink rgb(255,255,255),rgb(0,0,0)
  46.     print "Time to render ", end_timer, " milliseconds"
  47.  
  48.     wait key
  49.     save bitmap "fractal2.bmp"
  50.     end
  51.  
  52. `    End!
  53.  
  54. function calc_pixel(ca#,cbi#)
  55.  
  56. `    You can change max_iteration for a more detailed fractal
  57. `    Suggested values = 16, 32. 64, 128 & 256 (larger = slower)
  58.  
  59.     max_iteration=64
  60.  
  61.     a#=0
  62.     b#=0
  63.  
  64.     iteration#=0
  65.  
  66.     repeat
  67.         old_a# = a#
  68.         a# = a#*a# - b#*b# + ca#
  69.         b# = 2 * old_a#*b# + cbi#
  70.         length_z# = a#*a# + b#*b#
  71.  
  72.         inc iteration#
  73.  
  74.     until length_z#>4 or iteration#>max_iteration
  75.  
  76.     pixel_color#=iteration#
  77.  
  78. endfunction pixel_color#
  79.  
  80.